﻿using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaseHelper.Net
{
    public class ByteHelper
    {
        public static byte[] GetByteByHex(string hexString)
        {
            hexString = hexString.ToLower().Replace(" ", "").Replace("0x","").Replace(",","");
            if ((hexString.Length % 2) != 0)
                hexString += " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            return returnBytes;
        }

        public static string GetStringByByte(byte[] buffer,int len=0)
        {
            len = len == 0 ? buffer.Length : len;
            return BitConverter.ToString(buffer,0,len).Replace("-"," ");
        }

    }
}
